import React,{useReducer} from 'react';
import {initState,reducer,actions} from "./reducer/user"
import { Switch, Route, Redirect } from "react-router-dom"
let Login = React.lazy(() => import("./pages/Login/Login"))
let Register = React.lazy(() => import("./pages/Register/Register"))
let List = React.lazy(() => import("./pages/List/List"))
let Search = React.lazy(() => import("./pages/Search/Search"))
let Index = React.lazy(() => import("./pages/Index/Index"))
let Detail = React.lazy(() => import("./pages/Detail/Detail"))
let Youhui =React.lazy(()=>import('./pages/Youhui/Youhui'))
export const ReducerContext=React.createContext()
function App() {
  const [state, dispatch] = useReducer(reducer, initState)
  return (
    <div style={{touchAction:'none'}}>
       <ReducerContext.Provider value={ {state,dispatch,actions}}>
      <React.Suspense fallback={<div>正在加载。。。。。。</div>}>
      <Switch>
        <Route path='/login' component={Login}></Route>
        <Route path='/register' component={Register}></Route>
        <Route path='/list' component={List}></Route>
        <Route path='/search' component={Search}></Route>
        <Route path='/index' component={Index}></Route>
        <Route path='/detail' component={Detail}></Route>
        <Route path='/youhui' component={Youhui}></Route>
        <Redirect to='/login'></Redirect>
      </Switch>
    </React.Suspense >
    </ReducerContext.Provider>
    </div>
  );
}

export default App;
